import request from '../utls/require'

// 请求和响应类型定义
export interface LoginRequest {
  username: string
  password: string
}

export interface RegisterRequest {
  username: string
  password: string
  email?: string
}

export interface UserInfo {
  id: number
  username: string
  email: string
  is_staff: boolean
  is_superuser: boolean
}

export interface AuthResponse {
  success: boolean
  message: string
  data: UserInfo
}

export interface UserInfoResponse {
  success: boolean
  data: UserInfo
}

// 用户注册
export const register = (data: RegisterRequest) => {
  return request.post<any, AuthResponse>('/auth/register/', data)
}

// 用户登录
export const login = (data: LoginRequest) => {
  return request.post<any, AuthResponse>('/auth/login/', data)
}

// 用户登出
export const logout = () => {
  return request.post('/auth/logout/')
}

// 获取当前用户信息
export const getUserInfo = () => {
  return request.get<any, UserInfoResponse>('/auth/user/')
}